<?php

use Drupal\shusy_team_stats\Entity\ShusyTeamStats;

function shusy_team_stats_shusy_team_stats_entity_form($form, &$form_state, ShusyTeamStats $e, $op) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'shusy_team_stats') . '/shusy_team_stats.forms.inc';
  $form_state[ShusyTeamStats::class] = $e;

  $form['name'] = [
    '#type' => 'textfield',
    '#title' => t('地区'),
    '#required' => TRUE,
    '#default_value' => $e->name,
  ];
  $form['online'] = [
    '#type' => 'textfield',
    '#title' => t('在线'),
    '#required' => TRUE,
    '#default_value' => $e->online,
  ];
  $form['offline'] = [
    '#type' => 'textfield',
    '#title' => t('离线'),
    '#required' => TRUE,
    '#default_value' => $e->offline,
  ];

  field_attach_form($e->entityType(), $e, $form, $form_state);

  $form['actions'] = ['#type' => 'actions'];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('保存'),
  ];
  return $form;
}

function shusy_team_stats_shusy_team_stats_entity_form_submit($form, &$form_state) {
  $e = $form_state[ShusyTeamStats::class];
  if ($e instanceof ShusyTeamStats) {
    entity_form_submit_build_entity($e->entityType(), $e, $form, $form_state);
    $e->save();
  }
}

function shusy_team_stats_shusy_team_stats_delete_form($form, &$form_state, ShusyTeamStats $e) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'shusy_team_stats') . '/shusy_team_stats.forms.inc';
  $form_state[ShusyTeamStats::class] = $e;
  return confirm_form($form, t('Are you sure you want to delete %title?', ['%title' => $e->label()]), 'admin/content/shusy_team_stats/' . $e->id, t('This action cannot be undone.'), t('Delete'), t('Cancel'));
}

function shusy_team_stats_shusy_team_stats_delete_form_submit($form, &$form_state) {
  $e = $form_state[ShusyTeamStats::class];
  if ($e instanceof ShusyTeamStats) {
    $e->delete();
  }
  $form_state['redirect'] = 'admin/content/shusy_team_stats';
}

